﻿//菜单
var $SysMenu = {
    DealUrl: function (vueApp, url, type, param) {
        var my = vueApp;
        switch (url) {
            ////删除
            case '/api/SysMenu/DeleteMuti': Mock.mock(host + url, type, function (options) {
                var delIDs = options.body;
                var temp = [];
                for (var i = 0; i < $SysMenu.List.length; i++) {
                    temp.push($SysMenu.List[i]);
                }
                for (var i = 0; i < temp.length; i++) {

                    if (delIDs.includes(temp[i].Id)) {
                        $SysMenu.List.splice(temp[i], 1);
                    }
                }
                return { result: "Success", message: null, data: null };
            }); break;
            //获取List数据
            case '/api/SysMenu/GetList': Mock.mock(host + url, type,
                function (options) {
                    var delIDs = options.body;
                    if ($SysMenu.List.length == 0) {
                        $SysMenu.InitArray();
                    }
                    var p = JSON.parse(options.body);
                    //条件
                    var Name = p ? p.model.Name : null;
                    var Code = p ? p.model.Code : null;
                    var Type = p ? p.model.Type : null;
                    var ParentId = p ? p.model.ParentId : null;
                    var limitUsers2 = [];
                    for (var i = 0; i < $SysMenu.List.length; i++) {
                        var user = $SysMenu.List[i];
                        if (Name && user.Name.indexOf(Name) == -1)
                            continue;
                        if (Code && user.Code.indexOf(Code) == -1)
                            continue;
                        if (Type && user.Type.indexOf(Type) == -1)
                            continue;
                        if (ParentId && user.ParentId.indexOf(ParentId) == -1)
                            continue;
                        limitUsers2.push(user);
                    }
                    return {
                        result: "Success", message: null,
                        data: limitUsers2
                    };
                }); break;
            ////获取Input数据
            case '/api/SysMenu/get': Mock.mock(host + url + '?' + param, type, function (options) {
                var myUsers = parent.$SysMenu.List;
                myuser = {};
                for (var i = 0; i < myUsers.length; i++) {
                    if (myUsers[i].Id == vueApp.id) {
                        myuser = myUsers[i];
                        break;
                    }
                }
                return {
                    result: "Success", message: null, data: myuser
                };
            }); break;
            ////提交
            case '/api/SysMenu/Save': Mock.mock(host + url, type, function (options) {
                var thisuser = JSON.parse(options.body);
                var thisUsers = parent.$SysMenu.List;
                var cz = true;
                for (var i = 0; i < thisUsers.length; i++) {
                    if (thisUsers[i].Id == thisuser.Id) {
                        thisUsers[i].ParentId = thisuser.ParentId;
                        thisUsers[i].SerialNumber = thisuser.SerialNumber;
                        thisUsers[i].Name = thisuser.Name;
                        thisUsers[i].Code = thisuser.Code;
                        thisUsers[i].Url = thisuser.Url;
                        thisUsers[i].Type = thisuser.Type;
                        thisUsers[i].Icon = thisuser.Icon;
                        thisUsers[i].Remarks = thisuser.Remarks;
                        thisUsers[i].IsGroup = thisuser.IsGroup;
                        thisUsers[i].IsFactory = thisuser.IsFactory;
                        thisUsers[i].IsShare = thisuser.IsShare;
                        cz = false;
                        break;
                    }
                }
                if (cz) {
                    parent.$SysMenu.List.unshift({
                        Id: Mock.Random.id(),
                        ParentId: thisuser.ParentId ? thisuser.ParentId : guidEmpty,
                        SerialNumber: thisuser.SerialNumber,
                        Name: thisuser.Name,
                        Code: thisuser.Code,
                        Url: thisuser.Url,
                        Type: thisuser.Type,
                        Icon: thisuser.Icon,
                        Remarks: thisuser.Remarks,
                        IsGroup: thisuser.IsGroup,
                        IsFactory: thisuser.IsFactory,
                        IsShare: thisuser.IsShare,
                    });
                }
                return { result: "Success", message: null, data: null };
            }); break;
        }
    },
    List: [],
    InitArray: function () {
        $SysMenu.List = [
            { Id: '1', ParentId: guidEmpty, Name: 'A' },
            { Id: '2', ParentId: '1', Name: 'B' },
            { Id: '3', ParentId: '1', Name: 'C' },
            { Id: '4', ParentId: '2', Name: 'D' },
            { Id: '5', ParentId: '4', Name: 'E' },
            { Id: '6', ParentId: '5', Name: 'F' },
            { Id: '7', ParentId: guidEmpty, Name: 'G' }
        ]
        var parentids = [];
        for (var i = 0; i < 28; i++) {
            var Id = i + 'p';
            parentids.push(Id);
            $SysMenu.List.push(Mock.mock({
                Id: Id,
                ParentId: guidEmpty,
                SerialNumber: (i + 1),
                Name: '父级' + (i + 1),
                Code: '00' + (i + 1),
                Url: 'localhost:8080/' + (i + 1),
                Type: '0',
                Icon: 'icon-' + (i + 1),
                Remarks: Mock.mock('@cparagraph(1, 3)'),
                IsGroup: Mock.Random.boolean(),
                IsFactory: Mock.Random.boolean(),
                IsShare: Mock.Random.boolean(),
            }));

        }
        for (var i = 0; i < 15; i++) {
            $SysMenu.List.push(Mock.mock({
                Id: Mock.Random.id(),
                ParentId: parentids[Math.floor(Math.random() * parentids.length)],
                SerialNumber: (i + 1),
                Name: '子集' + i,
                Code: '10' + (i + 1),
                Url: 'localhost:8080/' + i,
                Type: '0',
                Icon: 'icon-' + i,
                Remarks: Mock.mock('@cparagraph(1, 3)'),
                IsGroup: Mock.Random.boolean(),
                IsFactory: Mock.Random.boolean(),
                IsShare: Mock.Random.boolean(),
            }));
        }
        //$SysMenu.List = MenuHelper($SysMenu.List, guidEmpty);
    }
}

//部门
var $SysDepartment = {
    DealUrl: function (vueApp, url, type, param) {
        var my = vueApp;
        switch (url) {
            ////删除
            case '/api/SysDepartment/DeleteMuti': Mock.mock(host + url, type, function (options) {
                var delIDs = options.body;
                var temp = [];
                for (var i = 0; i < $SysDepartment.List.length; i++) {
                    temp.push($SysMenu.List[i]);
                }
                for (var i = 0; i < temp.length; i++) {

                    if (delIDs.includes(temp[i].Id)) {
                        $SysDepartment.List.splice(temp[i], 1);
                    }
                }
                return { result: "Success", message: null, data: null };
            }); break;
            //获取List数据
            case '/api/SysDepartment/GetList': Mock.mock(host + url, type,
                function (options) {
                    var delIDs = options.body;
                    if ($SysDepartment.List.length == 0) {
                        $SysDepartment.InitArray();
                    }
                    var p = JSON.parse(options.body);
                    //条件
                    var Name = p ? p.model.Name : null;
                    var Code = p ? p.model.Code : null;
                    var Type = p ? p.model.Type : null;
                    var ParentId = p ? p.model.ParentId : null;
                    var limitUsers2 = [];
                    for (var i = 0; i < $SysDepartment.List.length; i++) {
                        var user = $SysDepartment.List[i];
                        if (Name && user.Name.indexOf(Name) == -1)
                            continue;
                        if (Code && user.Code.indexOf(Code) == -1)
                            continue;
                        if (Type && user.Type.indexOf(Type) == -1)
                            continue;
                        if (ParentId && user.ParentId.indexOf(ParentId) == -1)
                            continue;
                        limitUsers2.push(user);
                    }
                    return {
                        result: "Success", message: null,
                        data: limitUsers2
                    };
                }); break;
            ////获取Input数据
            case '/api/SysDepartment/get': Mock.mock(host + url + '?' + param, type, function (options) {
                var myUsers = parent.$SysDepartment.List;
                myuser = {};
                for (var i = 0; i < myUsers.length; i++) {
                    if (myUsers[i].Id == vueApp.id) {
                        myuser = myUsers[i];
                        break;
                    }
                }
                return {
                    result: "Success", message: null, data: myuser
                };
            }); break;
            ////提交
            case '/api/SysDepartment/Save': Mock.mock(host + url, type, function (options) {
                var thisuser = JSON.parse(options.body);
                var thisUsers = parent.$SysDepartment.List;
                var cz = true;
                for (var i = 0; i < thisUsers.length; i++) {
                    if (thisUsers[i].Id == thisuser.Id) {
                        thisUsers[i].ParentId = thisuser.ParentId;
                        thisUsers[i].Sort = thisuser.Sort;
                        thisUsers[i].Name = thisuser.Name;
                        thisUsers[i].Code = thisuser.Code;
                        thisUsers[i].CreateFactory = thisuser.CreateFactory;
                        thisUsers[i].Remark = thisuser.Remark;
                        cz = false;
                        break;
                    }
                }
                if (cz) {
                    parent.$SysDepartment.List.unshift({
                        Id: Mock.Random.id(),
                        ParentId: thisuser.ParentId ? thisuser.ParentId : guidEmpty,
                        Sort: thisuser.Sort,
                        Name: thisuser.Name,
                        Code: thisuser.Code,
                        CreateFactory: thisuser.CreateFactory,
                        Remark: thisuser.Remark,
                    });
                }
                return { result: "Success", message: null, data: null };
            }); break;
        }
    },
    List: [],
    InitArray: function () {
        $SysDepartment.List = [
            { Id: '1', ParentId: guidEmpty, Name: 'A' },
            { Id: '2', ParentId: '1', Name: 'B' },
            { Id: '3', ParentId: '1', Name: 'C' },
            { Id: '4', ParentId: '2', Name: 'D' },
            { Id: '5', ParentId: '4', Name: 'E' },
            { Id: '6', ParentId: '5', Name: 'F' },
            { Id: '7', ParentId: guidEmpty, Name: 'G' }
        ]
        var parentids = [];
        for (var i = 0; i < 28; i++) {
            var Id = i + 'p';
            parentids.push(Id);
            $SysDepartment.List.push(Mock.mock({
                Id: Id,
                ParentId: guidEmpty,
                Sort: (i + 1),
                Name: '父级' + (i + 1),
                Code: '00' + (i + 1),
                CreateFactory: Mock.Random.id(),
                Remark: Mock.mock('@cparagraph(1, 3)'),
            }));

        }
        for (var i = 0; i < 15; i++) {
            $SysDepartment.List.push(Mock.mock({
                Id: Mock.Random.id(),
                ParentId: parentids[Math.floor(Math.random() * parentids.length)],
                Sort: (i + 1),
                Name: '子集' + i,
                Code: '10' + (i + 1),
                CreateFactory: Mock.Random.id(),
                Remark: Mock.mock('@cparagraph(1, 3)'),
            }));
        }
    }
}
//字典
//var $SysDict = {
//    DealUrl: function (vueApp, url, type, param) {
//        var my = vueApp;
//        switch (url) {
//            ////删除
//            case '/api/SysDict/DeleteMuti': Mock.mock(host + url, type, function (options) {
//                var delIDs = options.body;
//                var temp = [];
//                for (var i = 0; i < $SysDict.List.length; i++) {
//                    temp.push($SysDict.List[i]);
//                }
//                for (var i = 0; i < temp.length; i++) {

//                    if (delIDs.includes(temp[i].Id)) {
//                        $SysDict.List.splice(temp[i], 1);
//                    }
//                }
//                return { result: "Success", message: null, data: null };
//            }); break;
//            //获取List数据
//            case '/api/SysDict/GetList': Mock.mock(host + url, type,
//                function (options) {
//                    var delIDs = options.body;
//                    if ($SysDict.List.length == 0) {
//                        $SysDict.InitArray();
//                    }
//                    var p = JSON.parse(options.body);
//                    //条件
//                    var Name = p ? p.model.Name : null;
//                    var Code = p ? p.model.Code : null;
//                    var Type = p ? p.model.Type : null;
//                    var ParentId = p ? p.model.ParentId : null;
//                    var limitUsers2 = [];
//                    for (var i = 0; i < $SysDict.List.length; i++) {
//                        var user = $SysDict.List[i];
//                        if (Name && user.Name.indexOf(Name) == -1)
//                            continue;
//                        if (Code && user.Code.indexOf(Code) == -1)
//                            continue;
//                        if (Type && user.Type.indexOf(Type) == -1)
//                            continue;
//                        if (ParentId && user.ParentId.indexOf(ParentId) == -1)
//                            continue;
//                        limitUsers2.push(user);
//                    }
//                    return {
//                        result: "Success", message: null,
//                        data: limitUsers2
//                    };
//                }); break;
//            ////获取Input数据
//            case '/api/SysDict/get': Mock.mock(host + url + '?' + param, type, function (options) {
//                console.log(vueApp.id)
//                var myUsers = parent.$SysDict.List;
//                myuser = {};
//                for (var i = 0; i < myUsers.length; i++) {
//                    if (myUsers[i].Code == vueApp.id) {
//                        myuser = myUsers[i];
//                        break;
//                    }
//                }
//                return {
//                    result: "Success", message: null, data: myuser
//                };
//            }); break;
//            ////提交
//            case '/api/SysDict/Save': Mock.mock(host + url, type, function (options) {
//                var thisuser = JSON.parse(options.body);
//                var thisUsers = parent.$SysDict.List;
//                var cz = true;
//                for (var i = 0; i < thisUsers.length; i++) {
//                    if (thisUsers[i].Code == thisuser.Code) {
//                        thisUsers[i].ParentCode = thisuser.ParentCode;
//                        thisUsers[i].Sort = thisuser.Sort;
//                        thisUsers[i].Name = thisuser.Name;
//                        thisUsers[i].Remark = thisuser.Remark;
//                        cz = false;
//                        break;
//                    }
//                }
//                if (cz) {
//                    parent.$SysDict.List.unshift({
//                        Code: Mock.Random.id(),
//                        ParentCode: thisuser.ParentCode ? thisuser.ParentCode : guidEmpty,
//                        Sort: thisuser.Sort,
//                        Name: thisuser.Name,
//                        Remark: thisuser.Remark,
//                    });
//                }
//                return { result: "Success", message: null, data: null };
//            }); break;
//        }
//    },
//    List: [],
//    InitArray: function () {
//        $SysDict.List = [
//            { Code: '1', ParentCode: guidEmpty, Name: 'A' },
//            { Code: '2', ParentCode: '1', Name: 'B' },
//            { Code: '3', ParentCode: '1', Name: 'C' },
//            { Code: '4', ParentCode: '2', Name: 'D' },
//            { Code: '5', ParentCode: '4', Name: 'E' },
//            { Code: '6', ParentCode: '5', Name: 'F' },
//            { Code: '7', ParentCode: guidEmpty, Name: 'G' }
//        ]
//        var parentids = [];
//        for (var i = 0; i < 28; i++) {
//            var Id = i + 'p';
//            parentids.push(Id);
//            $SysDict.List.push(Mock.mock({
//                Code: Id,
//                ParentCode: guidEmpty,
//                Sort: (i + 1),
//                Name: '父级' + (i + 1),
//                Remark: Mock.mock('@cparagraph(1, 3)'),
//            }));

//        }
//        for (var i = 0; i < 15; i++) {
//            $SysDict.List.push(Mock.mock({
//                Code: Mock.Random.id(),
//                ParentCode: parentids[Math.floor(Math.random() * parentids.length)],
//                Sort: (i + 1),
//                Name: '子集' + (i + 1),
//                Remark: Mock.mock('@cparagraph(1, 3)'),
//            }));
//        }
//    }
//}



var $SysDict = {
    DealUrl: function (vueApp, url, type, param) {
        var my = vueApp;
        switch (url) {
            ////删除
            case '/api/SysDict/DeleteMuti': Mock.mock(host + url, type, function (options) {
                var delIDs = options.body;
                var temp = [];
                for (var i = 0; i < $SysDict.List.length; i++) {
                    temp.push($SysDict.List[i]);
                }
                for (var i = 0; i < temp.length; i++) {

                    if (delIDs.includes(temp[i].Id)) {
                        $SysDict.List.splice(i, 1);
                    }
                }
                return { result: "Success", message: null, data: null };
            }); break;
            //获取List数据
            case '/api/SysDict/GetList': Mock.mock(host + url, type,
                function (options) {
                    if ($SysDict.List.length == 0) {
                        $SysDict.InitArray();
                    }
                    var p = JSON.parse(options.body);
                    //条件
                    var Name = p ? p.model.Name : null;
                    var Code = p ? p.model.Code : null;
                    var Type = p ? p.model.Type : null;
                    var ParentId = p ? p.model.ParentId : null;
                    var limitUsers2 = [];
                    for (var i = 0; i < $SysDict.List.length; i++) {
                        var user = $SysDict.List[i];
                        if (Name && user.Name.indexOf(Name) == -1)
                            continue;
                        if (Code && user.Code.indexOf(Code) == -1)
                            continue;
                        if (Type && user.Type.indexOf(Type) == -1)
                            continue;
                        if (ParentId && user.ParentId.indexOf(ParentId) == -1)
                            continue;
                        limitUsers2.push(user);
                    }
                    return {
                        result: "Success", message: null,
                        data: limitUsers2
                    };
                }); break;
            ////获取Input数据
            case '/api/SysDict/get': Mock.mock(host + url + '?' + param, type, function (options) {
                var myUsers = parent.$SysDict.List;

                console.log('myUsers', myUsers)
                console.log('vueApp.id', vueApp.id)
                myuser = {};
                for (var i = 0; i < myUsers.length; i++) {
                    if (myUsers[i].Id == vueApp.id) {
                        myuser = myUsers[i];
                        break;
                    }
                }
                console.log('myuser', myuser)
                return {
                    result: "Success", message: null, data: myuser
                };
            }); break;
            ////提交
            case '/api/SysDict/Save': Mock.mock(host + url, type, function (options) {
                var thisuser = JSON.parse(options.body);
                var thisUsers = parent.$SysDict.List;
                var cz = true;
                var changeSerialNumber = false;//是否修改数据排序
                thisUsers.find(function (obj) {
                    if (obj.SerialNumber == thisuser.SerialNumber)
                        changeSerialNumber = true;
                })
                //如果提交的排序已存在，则修改原数据中大于等于该排序的排序+1
                if (changeSerialNumber) {
                    for (var i = 0; i < thisUsers.length; i++) {
                        if (thisUsers[i].SerialNumber >= thisuser.SerialNumber) {
                            thisUsers[i].SerialNumber += 1;
                        }
                    }
                }
                for (var i = 0; i < thisUsers.length; i++) {
                    if (thisUsers[i].Id == thisuser.Id) {
                        thisUsers[i].SerialNumber = thisuser.SerialNumber;
                        thisUsers[i].Key = thisuser.Key;
                        thisUsers[i].Category = thisuser.Category;
                        thisUsers[i].Value = thisuser.Value;
                        thisUsers[i].Remarks = thisuser.Remarks;
                        cz = false;
                        break;
                    }
                }
                if (cz) {
                    parent.$SysDict.List.unshift({
                        Id: Mock.Random.id(),
                        SerialNumber: thisuser.SerialNumber,
                        Key: thisuser.Key,
                        Category: thisuser.Category,
                        Value: thisuser.Value,
                        Remarks: thisuser.Remarks,
                    });
                }
                return { result: "Success", message: null, data: null };
            }); break;
        }
    },
    List: [],
    InitArray: function () {
        $SysDict.List = [
            { Id: Mock.Random.id(), SerialNumber: 1, Key: '0', Category: '001', Value: '男', Remarks: Mock.mock('@cparagraph(1, 3)') },
            { Id: Mock.Random.id(), SerialNumber: 2, Key: '1', Category: '001', Value: '女', Remarks: Mock.mock('@cparagraph(1, 3)') },
            { Id: Mock.Random.id(), SerialNumber: 3, Key: '0', Category: '002', Value: '未开始', Remarks: Mock.mock('@cparagraph(1, 3)') },
            { Id: Mock.Random.id(), SerialNumber: 4, Key: '1', Category: '002', Value: '进行中', Remarks: Mock.mock('@cparagraph(1, 3)') },
            { Id: Mock.Random.id(), SerialNumber: 5, Key: '2', Category: '002', Value: '已完成', Remarks: Mock.mock('@cparagraph(1, 3)') },
            { Id: Mock.Random.id(), SerialNumber: 6, Key: '0', Category: '003', Value: '否', Remarks: Mock.mock('@cparagraph(1, 3)') },
            { Id: Mock.Random.id(), SerialNumber: 7, Key: '1', Category: '003', Value: '是', Remarks: Mock.mock('@cparagraph(1, 3)') },
            { Id: Mock.Random.id(), SerialNumber: 8, Key: '0', Category: '004', Value: 'A', Remarks: Mock.mock('@cparagraph(1, 3)') }
        ]

    }
}

